/**
 * Created by xuelei.kong on 2016/3/8.
 */
var express=require('express');
var path=require('path');
var port=process.env.PORT ||3000;
var app=express();
var mongoose=require('mongoose');
var Movie=require('./models/movie')
mongoose.connect('mongoose://localhost/imooc');
app.set('views',"./views/pages");
app.set("view engine",'jade');
//app.use(express.bodyParser());
app.use(express.static(path.join(__dirname,'bower_components')));
app.listen(port);
console.log('imooc started on port' +port);



/*首页*/
app.get('/', function (req, res) {
    Movie.fetch(function (err, movies) {
        if(err){
            console.log(err);
        }
        res.render('index',{
            title:"首页",
            movies:movies
            /* movies:[
             {title:"阿凡达1",_id:1,poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg"},
             {title:"阿凡达2",_id:2,poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg"},
             {title:"阿凡达3",_id:3,poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg"},
             {title:"阿凡达4",_id:4,poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg"},
             {title:"阿凡达5",_id:5,poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg"},
             ]*/
        });
    })

})
/*详情页*/
app.get('/movie/:id', function (req, res) {
    res.render('detail',{
        title:"电影详情页",
        movie:{
            doctor:"冯小刚",
            country:"USA",
            title:"阿凡达1",
            year:2014,
            poster:"https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
            flash:"http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
            summary: "adfasdafadfadfsasdf啊发发发发"
        }
    });
})


/*后台录入页*/
app.get('/admin/movie', function (req, res) {
    res.render('admin',{
        title:" 后台录入页",
        movie:{
            title:"1212",
            doctor:"",
            country:"",
            year:"",
            poster:"",
            flash:"",
            summary:"",
            language:""
        }
    });
})


/*列表页*/
app.get('/admin/list', function (req, res) {
    res.render('list',{
        title:"列表页",
        movies:[
            {
                title: "阿凡达1",
                _id: 1,
                doctor: "冯小刚",
                country: "USA",
                year: "2016",
                poster: "https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
                language: "English",
                flash: "http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
                summary: "adfasdafadfadfsasdf啊发发发发"
            },
            {
                title: "阿凡达2",
                _id: 2,
                doctor: "冯小刚",
                country: "USA",
                year: "2016",
                poster: "https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
                language: "English",
                flash: "http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
                summary: "adfasdafadfadfsasdf啊发发发发"
            },
            {
                title: "阿凡达3",
                _id: 3,
                doctor: "冯小刚",
                country: "USA",
                year: "2016",
                poster: "https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
                language: "English",
                flash: "http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
                summary: "adfasdafadfadfsasdf啊发发发发"
            },
            {
                title: "阿凡达4",
                _id: 4,
                doctor: "冯小刚",
                country: "USA",
                year: "2016",
                poster: "https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
                language: "English",
                flash: "http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
                summary: "adfasdafadfadfsasdf啊发发发发"
            },
            {
                title: "阿凡达5",
                _id: 5,
                doctor: "冯小刚",
                country: "USA",
                year: "2016",
                poster: "https://cbu01.alicdn.com/img/order/trading/970/808/6519062461/2389355899_722069522.jpg",
                language: "English",
                flash: "http://player.youku.com/player.php/Type/Folder/Fid/26378220/Ob/1/sid/XMTQ5MTc4MDIwMA==/v.swf",
                summary: "adfasdafadfadfsasdf啊发发发发"
            }
        ]
    });
})